﻿using System;
using System.Collections.Generic;
using System.Web;

/// <summary>
///系统用户
/// </summary>
/// 
public class UserData
{
    /// <summary>
    /// 标识
    /// </summary>
    public int id;

    /// <summary>
    /// 帐号名称
    /// </summary>
    public string name;

    /// <summary>
    /// 帐号密码
    /// </summary>
    public string password;

    /// <summary>
    /// 权限
    /// </summary>
    public int access;

    /// <summary>
    /// 微博帐号列表
    /// </summary>
    public List<BlogAccountData> blogAccountList = new List<BlogAccountData>();

	public UserData()
	{
		
	}

    public UserData(string name, string password)
    {
        this.name = name;
        this.password = password;
    }

    public UserData(string name, string password, int right):this(name, password)
    {
        this.access = right;
    }

    public UserData(int id, string name, string password, int right):this(name, password, right)
    {
        this.id = id;
    }

    private string getBlogAccountString()
    {
        if (blogAccountList == null || blogAccountList.Count == 0)
            return "";
        else
        {
            string result = "";
            for (int i = 0; i < blogAccountList.Count; i++)
            {
                result += blogAccountList[i].toJson();
                if (i < blogAccountList.Count - 1)
                    result += ",";
            }
            return result;
        }
    }

    public string toJson()
    {
        return "{" + string.Format("\"id\":{0}, \"name\":\"{1}\", \"access\":{2}, \"blogAccountList\":[{3}]", id, name, access, getBlogAccountString()) + "}";
    }
}